package org.jeecg.modules.system.util;


import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import org.jeewx.api.core.common.AccessToken;
import org.jeewx.api.core.exception.WexinReqException;
import org.jeewx.api.wxsendmsg.JwSendTemplateMsgAPI;
import org.jeewx.api.wxuser.user.JwUserAPI;
import org.jeewx.api.wxuser.user.model.Wxuser;

import java.util.List;

/**
 * @Description: 密码加密解密
 * @author: lsq
 * @date: 2020年09月07日 14:26
 */
public class SecurityUtil {
    /**加密key*/
    private static String key = "JEECGBOOT1423670";

    //---AES加密---------begin---------
    /**加密
     * @param content
     * @return
     */
    public static String jiami(String content) {
            SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key.getBytes());
            String encryptResultStr = aes.encryptHex(content);
            return encryptResultStr;
    }

    /**解密
     * @param encryptResultStr
     * @return
     */
    public static String jiemi(String encryptResultStr){
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key.getBytes());
        //解密为字符串
        String decryptResult = aes.decryptStr(encryptResultStr, CharsetUtil.CHARSET_UTF_8);
        return  decryptResult;
    }
    //---AES加密---------end---------
    /**
     * 主函数
     */
    public static void main(String[] args) {
        String content="test1111";
        //String encrypt = jiami(content);
        //System.out.println(encrypt);
        ////构建
        //String decrypt = jiemi(encrypt);
        ////解密为字符串
        //System.out.println(decrypt);

        String appid="wxbc93defb209eb818";

        String appscret="168fb6f9d7dca318be78ad26b01c7618";
        AccessToken at=new AccessToken(appid,appscret);

        //获取AccessToken
        String newAccessToken = null;// at.getNewAccessToken();
        //System.out.println("newAccessToken:"+newAccessToken);
        //String newAccessToken="55_iOpMAE9QnBb8RUG3oJg740VsbBUmf2EDdo3VI6QW8T90UjY3I7CTssU5TpexBXikKqvxKe5sWw5W_gFOZ5sNFrnZq5GiP1HbN1pCZFH6B4vDEXhmfuopz0gbHATFGcrciiRb0t0uFb9UH0jZKXEaAEAVIP";

        newAccessToken="55_9MO41CGey5di78Wh7Q8xcC14cudSviZCyQeoWdcld_ILgLij1qAIyWbWbKtqBqsJA7Mnb1dXB_Cn6DWwT2Y81vkwKJaXzxJT5TeFucDTIqg5dKBIzCZZIn-gra0mv8mMUag_fINGvPS3FW8gUKPcABABRW";
        try {
            String getTemplateList = JwSendTemplateMsgAPI.getTemplateList(newAccessToken);

            System.out.println("getTemplateList:"+getTemplateList);


            Wxuser wxuser = JwUserAPI.getWxuser(newAccessToken, "oeoa50xyntrLUkCrswKdVZLAqch4");
            List<Wxuser> allWxuser = JwUserAPI.getAllWxuser(newAccessToken, "oeoa50xyntrLUkCrswKdVZLAqch4");
            System.out.println(wxuser.getNickname());

            //发送模板信息
            //JwTemplateMessageAPI tma=new JwTemplateMessageAPI();
            ////String templateId="4m3vrpiSA-CPyL9YqHw2jKDlZSX6Sz65SoMKvA9BV1s";
            //String openId="oR0jFtxn8q_UsSXsKT395GVaG8q0";
            //
            //String accessToken  = "qCU9cEJzhGSJxncRzuxC2Yx5zB4LNysB1_GVTYeRwWtsRydB7c7C6q2WlRFeX7XQg7edLiOQcO5juf0BcMXcWMgR8lEe3qutVMwR88WVCy0";
            //IndustryTemplateMessageSend industryTemplateMessageSend = new IndustryTemplateMessageSend();
            //industryTemplateMessageSend.setAccess_token(accessToken);
            //industryTemplateMessageSend.setTemplate_id(templateId);
            //industryTemplateMessageSend.setTouser(openId);
            //industryTemplateMessageSend.setUrl("www.baidu.com");
            //industryTemplateMessageSend.setTopcolor("#ffAADD");
            //
            //TemplateMessage data = new TemplateMessage();
            //TemplateData first = new TemplateData();
            //first.setColor("#173177");
            //first.setValue("恭喜你购买成2323功！");
            //TemplateData keynote1 = new TemplateData();
            //keynote1.setColor("#173177");
            //keynote1.setValue("巧克22力");
            //TemplateData keynote2 = new TemplateData();
            //keynote2.setColor("39.8元");
            //keynote2.setValue("恭喜你购买成功！");
            //TemplateData keynote3 = new TemplateData();
            //keynote3.setColor("#173177");
            //keynote3.setValue("2014年9月16日");
            //TemplateData remark = new TemplateData();
            //remark.setColor("#173177");
            //remark.setValue("欢迎再次购买！");
            //data.setFirst(first);
            //data.setKeynote1(keynote1);
            //data.setKeynote2(keynote2);
            //data.setKeynote3(keynote3);
            //data.setRemark(remark);
            //
            //industryTemplateMessageSend.setData(data);
            //tma.sendTemplateMsg(industryTemplateMessageSend);

        } catch (WexinReqException e) {
            e.printStackTrace();
        }




    }
}
